<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: class.price.php 541 2015-02-28 11:57:24Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 541 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2015-02-28 11:57:24 +0000 (Sat, 28 Feb 2015) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'class.price.ext.php');

class price {

	var $currencies;
	var $db;

	function __construct($currency, $cGroup, $db = '') {
		global $db;
		$this->currencies = array();
		$this->cStatus = array();
		$this->actualGroup = $cGroup;
		$this->actualCurr = $currency;
		$this->TAX = array();
		$this->SHIPPING = array();
		$this->showFrom_Attributes = true;
		$this->db = $db;
		$this->_ext = new price_ext($this);

		$currencies = $this->db->db_query("SELECT
												title,
												code,
												symbol_left,
												symbol_right,
												decimal_point,
												thousands_point,
												decimal_places,
												value
											FROM
												".TABLE_CURRENCIES, true);

		while(!$currencies->EOF) {
			
			$this->currencies[$currencies->fields['code']] = array ('title' => $currencies->fields['title'],
																	'symbol_left' => $currencies->fields['symbol_left'],
																	'symbol_right' => $currencies->fields['symbol_right'],
																	'decimal_point' => $currencies->fields['decimal_point'],
																	'thousands_point' => $currencies->fields['thousands_point'],
																	'decimal_places' => $currencies->fields['decimal_places'],
																	'value' => $currencies->fields['value']);
			$currencies->MoveNext();
		}

		$customers_status_value = $this->db->db_query("SELECT
															*
														FROM
															".TABLE_CUSTOMERS_STATUS."
														WHERE
															customers_status_id = '".$this->actualGroup."'
														AND
															language_id = '".$_SESSION['languages_id']."'", true);

		$this->cStatus = array(	'customers_status_id' => $this->actualGroup,
								'customers_status_name' => $customers_status_value->fields['customers_status_name'],
								'customers_status_image' => $customers_status_value->fields['customers_status_image'],
								'customers_status_public' => $customers_status_value->fields['customers_status_public'],
								'customers_status_discount' => $customers_status_value->fields['customers_status_discount'],
								'customers_status_ot_discount_flag' => $customers_status_value->fields['customers_status_ot_discount_flag'],
								'customers_status_ot_discount' => $customers_status_value->fields['customers_status_ot_discount'],
								'customers_status_graduated_prices' => $customers_status_value->fields['customers_status_graduated_prices'],
								'customers_status_show_price' => $customers_status_value->fields['customers_status_show_price'],
								'customers_status_show_price_tax' => $customers_status_value->fields['customers_status_show_price_tax'],
								'customers_status_add_tax_ot' => $customers_status_value->fields['customers_status_add_tax_ot'],
								'customers_status_payment_unallowed' => $customers_status_value->fields['customers_status_payment_unallowed'],
								'customers_status_shipping_unallowed' => $customers_status_value->fields['customers_status_shipping_unallowed'],
								'customers_status_discount_attributes' => $customers_status_value->fields['customers_status_discount_attributes'],
								'customers_fsk18' => $customers_status_value->fields['customers_fsk18'],
								'customers_fsk18_display' => $customers_status_value->fields['customers_fsk18_display']);

		$zones = $this->db->db_query("SELECT tax_class_id AS class FROM ".TABLE_TAX_CLASS);
		while(!$zones->EOF) {
			if (isset($_SESSION['billto']) && isset($_SESSION['sendto'])) {
				$tax_address = $this->db->db_query("SELECT
														ab.entry_country_id,
														ab.entry_zone_id
													FROM
														".TABLE_ADDRESS_BOOK." ab
														LEFT JOIN ".TABLE_ZONES." z ON (ab.entry_zone_id = z.zone_id)
													WHERE
														ab.customers_id = '".(int)$_SESSION['customer_id']."'
													AND
														ab.address_book_id = '".($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto'])."'", true);

				$this->TAX[$zones->fields['class']] = get_tax_rate($zones->fields['class'], $tax_address->fields['entry_country_id'], $tax_address->fields['entry_zone_id']);
			} else {
				$country_id = -1; 
				if (isset($_SESSION['country']) && !isset($_SESSION['customer_id']))
					$country_id = $_SESSION['country'];
				$this->TAX[$zones->fields['class']] = get_tax_rate($zones->fields['class'], $country_id);
			}
			$zones->MoveNext();
		}
	}

	function GetPrice($pID, $format = true, $qty = 1, $tax_class = 0, $pPrice = 0, $vpeStatus = 0, $cedit_id = 0, $price_type = '') {
		// Darf Kunde Preise sehen?
		if ($this->cStatus['customers_status_show_price'] == '0')
			return $this->ShowNote($vpeStatus, $vpeStatus);

		// Steuern ermitteln
		if ($cedit_id != 0) {
			require_once (DIR_FS_INC.'inc.oe_customer_infos.php');
			$cinfo = oe_customer_infos($cedit_id);
			$products_tax = get_tax_rate($tax_class, $cinfo['country_id'], $cinfo['zone_id']);

		} else
			$products_tax = $this->TAX[$tax_class];

		if ($this->cStatus['customers_status_show_price_tax'] == '0')
			$products_tax = '';

		// Steuern hinzufügen
		if($pPrice == 0)
			$pPrice = $this->format($this->getPprice($pID), false);

		$pPrice = $this->AddTax($pPrice, $products_tax, $qty);
		if ($sPrice = $this->CheckSpecial($pID))
			return $this->formatSpecial($pID, $this->AddTax($sPrice, $products_tax), $pPrice, $format, $vpeStatus, $qty);
		
		// Gruppenpreis
		if($gPrice = $this->GroupPrice($pID, 1))
			return $this->format($this->AddTax($gPrice, $products_tax), $format, 0, false, $vpeStatus, $pID, $price_type);

		// Staffelpreise
		if($this->cStatus['customers_status_graduated_prices'] == '1') {
			if($staffelPreis = $this->GetGroupPrice($pID, $qty))
				return $this->formatSpecialGraduated($pID, $this->AddTax($staffelPreis, $products_tax), $pPrice, $format, $vpeStatus, $price_type);
		}
		if($discount = $this->CheckDiscount($pID))
			return $this->formatSpecialDiscount($pID, $discount, $pPrice, $format, $vpeStatus);
		
		return $this->format($pPrice, $format, 0, false, $vpeStatus, $pID, $price_type);
	}

  function getPprice($pID) {
  		$pData = $this->db->db_query("SELECT products_price FROM ".TABLE_PRODUCTS." WHERE products_id = '".$pID."'", true);
  		return $pData->fields['products_price'];
  	}

	function AddTax($price, $tax, $qty = 1) {
		$price = ($price + (($price / 100) * $tax))*$qty;
		$price = $this->CalculateCurr($price);
		return round($price, $this->currencies[$this->actualCurr]['decimal_places']);
	}

	function CheckDiscount($pID) {
		if($this->cStatus['customers_status_discount'] != '0.00') {
			$discount = $this->db->db_query("SELECT products_discount_allowed FROM ".TABLE_PRODUCTS." WHERE products_id = '".$pID."'", true);

			if($this->cStatus['customers_status_discount'] < $discount->fields['products_discount_allowed'])
				$discount->fields['products_discount_allowed'] = $this->cStatus['customers_status_discount'];
			if($discount->fields['products_discount_allowed'] == '0.00')
				return false;
			return $discount->fields['products_discount_allowed'];
		}
		return false;
	}
	
	function GroupPrice($pID, $qty) {
		if($qty != 1)
			return;

		$group_price = $this->db->db_query("SELECT 
													personal_offer 
												FROM 
													".TABLE_PERSONAL_OFFERS_BY.$this->actualGroup." 
												WHERE 
													products_id = '".$pID."'
												AND
													quantity = '1'
												AND 
													personal_offer != '0.0000'", true);

		if($group_price->_numOfRows == 1)
			return $group_price->fields['personal_offer'];
		else
			return;
	}
	
	function GetGroupPrice($pID, $qty) {
				
		$graduated_price = $this->db->db_query("SELECT 
													MAX(quantity) AS qty 
												FROM 
													".TABLE_PERSONAL_OFFERS_BY.$this->actualGroup." 
												WHERE 
													products_id = '".$pID."' 
												AND 
													quantity <= '".$qty."'", true);
		$check = $this->db->db_query("SELECT 
											personal_offer 
										FROM 
											".TABLE_PERSONAL_OFFERS_BY.$this->actualGroup." 
										WHERE 
											products_id = '".$pID."'", true);
											
		if($graduated_price->_numOfRows && $check->_numOfRows > 1) {
			$sPrice = $this->db->db_query("SELECT 
												personal_offer 
											FROM 
												".TABLE_PERSONAL_OFFERS_BY.$this->actualGroup." 
											WHERE 
												products_id = '".$pID."' 
											AND 
												quantity = '".$graduated_price->fields['qty']."'", true);
												
			return $sPrice->fields['personal_offer'];
		
		} else
			return false;
	}

	function GetOptionPrice($pID, $option, $value) {
		$attribute_price = $this->db->db_query("SELECT
													pd.products_discount_allowed,
													pd.products_tax_class_id,
													p.options_values_price,
													p.price_prefix,
													p.options_values_weight,
													p.weight_prefix
												FROM
													".TABLE_PRODUCTS_ATTRIBUTES." p,
													".TABLE_PRODUCTS." pd
												WHERE
													p.products_id = '".$pID."'
												AND
													p.options_id = '".$option."'
												AND
													pd.products_id = p.products_id
												AND
													p.options_values_id = '".$value."'", true);

		$dicount = 0;
		if($this->cStatus['customers_status_discount_attributes'] == 1 && $this->cStatus['customers_status_discount'] != 0.00) {
			$discount = $this->cStatus['customers_status_discount'];
			if($attribute_price->fields['products_discount_allowed'] < $this->cStatus['customers_status_discount'])
				$discount = $attribute_price->fields['products_discount_allowed'];
		}
		$price = $this->format($attribute_price->fields['options_values_price'], false, $attribute_price->fields['products_tax_class_id']);
		if ($attribute_price->fields['weight_prefix'] != '+')
			$attribute_price->fields['options_values_weight'] *= -1;
		if ($attribute_price->fields['price_prefix'] == '+')
			$price = $price - $price / 100 * $discount;
		else
			$price *= -1;

		return array ('weight' => $attribute_price->fields['options_values_weight'], 'price' => $price);
	}

	function ShowNote($vpeStatus, $vpeStatus = 0) {
		if ($vpeStatus == 1)
			return array ('formated' => NOT_ALLOWED_TO_SEE_PRICES, 'plain' => 0);
		return NOT_ALLOWED_TO_SEE_PRICES;
	}

	/*
		@return special Price
	*/
	function CheckSpecial($pID) {
		$product = $this->db->db_query("SELECT specials_price_".$this->actualGroup." FROM ".TABLE_SPECIALS." WHERE products_id = '".$pID."' AND status = 1", true);
		if($product->fields['specials_price_'.$this->actualGroup] !='0.0000')
			return $product->fields['specials_price_'.$this->actualGroup];
	}

	/**
	* @return array (products_id, price[regular, special], discount[absolut, percent]) or empty arrray
	*/
	function CheckSpecialProduktGroup($pID) {
		$retVal = array();
		$min_discount = 1.0;
		$sql = "
			select distinctrow
				pd.products_id, pd.products_price, 
				s.specials_price_".$this->actualGroup." s_price
			from 
				(mercari_products ps
					left join mercari_products_to_models p2m on ps.products_id = p2m.products_id
					left join mercari_products pd on (pd.products_id = p2m.products_model or pd.products_id = ps.products_id))
				inner join mercari_specials s on s.products_id = pd.products_id
			where
				ps.products_id = '".$pID."'
				and specials_price_".$this->actualGroup." !='0.0000'
				and status = 1";

		$query = $this->db->db_query($sql, true);
		while(!$query->EOF) {
			if ( ($query->fields['s_price'] / $query->fields['products_price']) < $min_discount) {
				$min_discount = $query->fields['s_price'] / $query->fields['products_price'];
				$retVal = array(
					'products_id' => $query->fields['products_id'],
					'price' => array('regular' => $query->fields['products_price'], 'special' => $query->fields['s_price']),
					'discount' => array(
						'absolut_netto' => $query->fields['products_price'] - $query->fields['s_price'], 
						'percent' => 1.0-$min_discount),
				);
			}
				$query->MoveNext();
		}
		return $retVal;
	}

	function CalculateCurr($price) {
		return $this->currencies[$this->actualCurr]['value'] * $price;
	}

	function calcTax($price, $tax) {
		return ($price * ($tax / ($tax+100)));
	}

	function RemoveCurr($price) {
		if (DEFAULT_CURRENCY != $this->actualCurr)
			return $price * (1 / $this->currencies[$this->actualCurr]['value']);
		else
			return $price;
	}

	function RemoveTax($price, $tax) {
		$price = (($price / ($tax+100))*100);
		return $price;
	}

	function GetTax($price, $tax) {
		$tax = $price - $this->RemoveTax($price, $tax);
		return $tax;
	}

	function GetDiscount($price,$discount_customers,$products=array()) {
    //Kundenrabatt
		$discount = $price/100*$discount_customers;

		return $discount;
	}

	function checkAttributes($pID) {
		if(!$this->showFrom_Attributes)
			return;

		if($pID == 0)
			return;

		$products_attributes = $this->db->db_query("SELECT
													COUNT(*) AS total,
													SUM(patrib.options_values_price) AS summe
												FROM
												 	".TABLE_PRODUCTS_OPTIONS." popt,
												 	".TABLE_PRODUCTS_ATTRIBUTES." patrib
												 WHERE
												 	patrib.products_id='".$pID."'
												 AND
												 	patrib.options_id = popt.products_options_id
												 AND
												 	popt.language_id = '".(int) $_SESSION['languages_id']."'", true);

		if(($products_attributes->fields['total'] > 0) && ($products_attributes->fields['summe'] > 0))
			return ' '.FROM.' ';
	}

	function CalculateCurrEx($price, $curr) {
		return $price * ($this->currencies[$curr]['value'] / $this->currencies[$this->actualCurr]['value']);
	}

	/**
	  Format Functions
	**/
	function format($price, $format, $tax_class = 0, $curr = false, $vpeStatus = 0, $pID = 0, $price_type = '') {
		if ($curr)
			$price = $this->CalculateCurr($price);

		if ($tax_class != 0) {
			$products_tax = $this->TAX[$tax_class];
			if ($this->cStatus['customers_status_show_price_tax'] == '0')
				$products_tax = '';
				
			$price = $this->AddTax($price, $products_tax);
		}
		if($format) {
			$Pprice = number_format((double)$price, $this->currencies[$this->actualCurr]['decimal_places'], $this->currencies[$this->actualCurr]['decimal_point'], $this->currencies[$this->actualCurr]['thousands_point']);
			$Pprice = $this->checkAttributes($pID).$this->currencies[$this->actualCurr]['symbol_left'].($this->currencies[$this->actualCurr]['symbol_left']!=''?' ':'').$Pprice.' '.$this->currencies[$this->actualCurr]['symbol_right'];
			if ($vpeStatus == 0)
				return $Pprice;
			else {
				if(PRICE_AS_IMAGE == 'true' && isset($price_type))
					return $this->PriceAsImage($pID, $Pprice, $this->currencies[$this->actualCurr]['symbol_right'], $price_type, '');
				else
					return array('formated' => $Pprice, 'plain' => $price, 'cur_sm_right' => $this->currencies[$this->actualCurr]['symbol_right']);
			}
		} 
		else {
		  $d = round($price, $this->currencies[$this->actualCurr]['decimal_places']);
			return $d;
		}
	}

	function PriceAsImage($pID = '0', $price, $curr_code = '', $price_type = '', $attr = '') {
		if($price_type == 'info')
			$imagePath = 'templates/'.CURRENT_TEMPLATE.'/img/numbers/big/';
		else
			$imagePath = 'templates/'.CURRENT_TEMPLATE.'/img/numbers/small/';

		$price = explode(' ', trim((string)$price));

		if ($this->currencies[$this->actualCurr]['symbol_left'] != '') {
			$_curr = trim($price[0]);
			$price = $price[1];

		} elseif ($this->currencies[$this->actualCurr]['symbol_right'] != '') {
			$_curr = trim($price[1]);
			$price = $price[0];
		}

		$price = explode($this->currencies[$this->actualCurr]['decimal_point'], trim($price));

		$suffix = $price[1];
		$prefix = str_replace($this->currencies[$this->actualCurr]['thousands_point'], '', $price[0]);
		$pre = '';
		for ($i = 0; $i < strlen($prefix); $i++)
			$pre.= image($imagePath.substr($prefix, $i, 1).'.gif', substr($prefix, $i, 1));

		// Dezimalpunkt
		if($this->currencies[$this->actualCurr]['decimal_point'] == '.')
			$point = 'point';
		else
			$point = $this->currencies[$this->actualCurr]['decimal_point'];

		if (file_exists($imagePath.$point.'.gif'))
			$pre.= image($imagePath.$point.'.gif', $this->currencies[$this->actualCurr]['decimal_point']);
		else
			$pre.= $this->currencies[$this->actualCurr]['decimal_point'];

		// Nachkommastellen
		$su = '';
		if($suffix[0] == 0 && $suffix[1] == 0)
			$su.= image($imagePath.'-.gif', '-');
		else {
			for ($i = 0; $i < strlen($suffix); $i++)
				$su.= image($imagePath.substr($suffix, $i, 1).'_sub.gif', substr($suffix, $i, 1));
		}

		// Währung
		if($_curr == '') {
			if($this->currencies[$this->actualCurr]['symbol_left'] != "")
				$_curr = trim($this->currencies[$this->actualCurr]['symbol_left']);
			else
				$_curr = trim($this->currencies[$this->actualCurr]['symbol_right']);
		}
		if(file_exists($imagePath.strtolower($_curr).".gif"))
			$curr = image($imagePath.strtolower($_curr).'.gif', strtolower($_curr));
		else
			$curr = $_curr;

		// Attribut da?
		if($attr !='') {
			if(file_exists($imagePath.trim(strtolower($attr)).".gif"))
				$attr = image($imagePath.trim(strtolower($attr)).'.gif', strtolower($attr));
			else
				$attr = $attr;
		} elseif($this->checkAttributes($pID)) {
			if($attr !='')
				if(file_exists($imagePath.trim(strtolower($this->checkAttributes($pID))).".gif"))
					$attr = image($imagePath.trim(strtolower($this->checkAttributes($pID))).'.gif', strtolower($this->checkAttributes($pID)));
				else
					$attr = $attr;
		}

		// Zusammensetzen
		if($this->currencies[$this->actualCurr]['symbol_left'] != "")
			return $attr.$curr.$pre.$su;
		else
			return $attr.$pre.$su.$curr;

	}

	function formatSpecialDiscount($pID, $discount, $pPrice, $format, $vpeStatus = 0) {
		$sPrice = $pPrice - ($pPrice / 100) * $discount;
		if($format){
			$price = '	<span class="product_price_new">'.$this->checkAttributes($pID).$this->format($sPrice, $format).'</span> 
						<span class="product_price_old">'.INSTEAD.' '.$this->format($pPrice, $format).'</span>
						<span class="product_price_discount">'.BOX_LOGINBOX_DISCOUNT.': '.round($discount).'%</span>';
			if($vpeStatus == 0)
				return $price;
			else
				return array('formated' => $price, 'plain' => $sPrice);

		} else
			return round($sPrice, $this->currencies[$this->actualCurr]['decimal_places']);
	}

	function formatSpecial($pID, $sPrice, $pPrice, $format, $vpeStatus = 0, $qty = 1) {
		if($price_type == 'info')
			$imagePath = 'templates/'.CURRENT_TEMPLATE.'/img/numbers/big/';
		else
			$imagePath = 'templates/'.CURRENT_TEMPLATE.'/img/numbers/small/';
		if($format) {
			if(PRICE_AS_IMAGE == 'true') {
				$sPrice_raw = $sPrice;
				$sPrice = number_format($sPrice, $this->currencies[$this->actualCurr]['decimal_places'], $this->currencies[$this->actualCurr]['decimal_point'], $this->currencies[$this->actualCurr]['thousands_point']);

				$price = '
					<span class="product_price_old">
						<small>'.INSTEAD.'</small>
						<del>'.$this->format($pPrice, $format).'</del>
					</span>
					<span class="product_price_real">
						'.$this->PriceAsImage($pID, $sPrice, $this->currencies[$this->actualCurr]['symbol_right'], $price_type).'
					</span>
					<span class="product_price_save">
						'.YOU_SAVE.round(($pPrice-$sPrice_raw) / $pPrice * 100,1).'%
					</span>';
				return $price;

			} else {
				$price = '<span class="product_price_new">'.$this->checkAttributes($pID).$this->format($sPrice, $format).'</span> 
						<span class="product_price_old">'.INSTEAD.' '.$this->format(($pPrice*$qty), $format).'</span>';
				if ($vpeStatus == 0)
					return $price;
				else
					return array('formated' => $price, 'plain' => $sPrice);
			}
			
		} else
			return round($sPrice, $this->currencies[$this->actualCurr]['decimal_places']);
	}

	function formatSpecialGraduated($pID, $sPrice, $pPrice, $format, $vpeStatus = 0, $price_type) {
		
		$tax_class = $this->db->db_query("SELECT products_tax_class_id FROM ".TABLE_PRODUCTS." WHERE products_id = '".$pID."' ", true);
		
		if($pPrice == 0)
			return $this->format($sPrice, $format, 0, false, $vpeStatus, $price_type);

		if ($discount = $this->CheckDiscount($pID))
			$sPrice -= $sPrice / 100 * $discount;

		if($format) {
			if($this->actualGroup =='0')
				$gruppe = '1';
			else
				$gruppe = $this->actualGroup;

			$pPriceRaw = $pPrice;
			$sPriceRaw = $sPrice;
			$sPrice = number_format($sPrice, $this->currencies[$this->actualCurr]['decimal_places'], $this->currencies[$this->actualCurr]['decimal_point'], $this->currencies[$this->actualCurr]['thousands_point']);
			$pPrice = number_format($pPrice, $this->currencies[$this->actualCurr]['decimal_places'], $this->currencies[$this->actualCurr]['decimal_point'], $this->currencies[$this->actualCurr]['thousands_point']);


			$sQuery = $this->db->db_query("SELECT max(quantity) as qty FROM ".TABLE_PERSONAL_OFFERS_BY.$gruppe." WHERE products_id='".$pID."'", true);

			if(PRICE_AS_IMAGE == 'true') {
				if(($this->cStatus['customers_status_graduated_prices'] == '1') && ($sQuery->fields['qty'] > 1)) {
					$bestPrice = $this->GetGroupPrice($pID, $sQuery->fields['qty']);
					if ($discount)
						$bestPrice -= $bestPrice / 100 * $discount;
					$bestPrice = number_format($bestPrice, $this->currencies[$this->actualCurr]['decimal_places'], $this->currencies[$this->actualCurr]['decimal_point'], $this->currencies[$this->actualCurr]['thousands_point']);
					return $this->PriceAsImage($pID, $bestPrice, $this->currencies[$this->actualCurr]['symbol_right'], 'info', FROM).' <br />
							<span class="single_price">'.$this->PriceAsImage($pID, $sPrice, $this->currencies[$this->actualCurr]['symbol_right'], 'box', SINGLE_PRICE)	.'</span>';

				} elseif ($sPrice != $pPrice) {
					return '<span class="product_price_old">'.MSRP.' '.$this->PriceAsImage($pID, $pPrice, $this->currencies[$this->actualCurr]['symbol_right'], '', FROM).'</span>
							<br />'.YOUR_PRICE.$this->checkAttributes($pID).$this->PriceAsImage($pID, $sPrice, $this->currencies[$this->actualCurr]['symbol_right'], 'info', FROM);
				}
				else
					return $this->PriceAsImage($pID, $sPrice, '');

			} else {
				if(($this->cStatus['customers_status_graduated_prices'] == '1') && ($sQuery->fields['qty'] > 1)) {
					$bestPrice = $this->GetGroupPrice($pID, $sQuery->fields['qty']);
					if ($discount)
						$bestPrice -= $bestPrice / 100 * $discount;
					$price .= '<span class="from_single_price">'.FROM.' '.$this->format($bestPrice, $format, $tax_class->fields['products_tax_class_id']).'</span> <span class="single_price">('.SINGLE_PRICE.$this->format(($sPriceRaw != $pPriceRaw ? $sPriceRaw : $pPriceRaw), $format).')</span>';
					
				} else if ($sPriceRaw != $pPriceRaw)
					$price = '<span class="product_price_old">'.MSRP.' '.$this->format($pPriceRaw, $format).'</span><br />'.YOUR_PRICE.$this->checkAttributes($pID).$this->format($sPriceRaw, $format);
					
				else
					$price = $this->format($sPriceRaw, $format);
			}
			if ($vpeStatus == 0)
				return $price;
			else
				return array('formated' => $price, 'plain' => $sPrice);
		} else
			return $sPrice;
	}

	function get_decimal_places($code) {
		return $this->currencies[$this->actualCurr]['decimal_places'];
	}
}?>